import os,glob
import csv

class_to_num ={}
classname_list = os.listdir("mydata")
print(classname_list)
for cs in classname_list :
    class_to_num[cs] = len(class_to_num.keys())

print(class_to_num) # {'dog': 0, 'cat': 1}
image_dir = []
for cs in classname_list :
    image_dir += (glob.glob(os.path.join("mydata",cs,"*.*")))

print(image_dir)
with open("mydata.csv","w",newline="") as f:
    writer = csv.writer(f)
    writer.writerow(["image_path","class_num"])
    for image_path in image_dir:
        class_name = image_path.split(os.sep)[-2]
        class_num = class_to_num[class_name]
        writer.writerow([image_path,class_num])
